package cn.yj.core.business.controller;

import cn.yj.commons.utils.FileUtils;
import cn.yj.config.ConcatInfo;
import cn.yj.config.annotation.Anonymous;
import cn.yj.config.web.AppBaseController;
import cn.yj.core.business.service.SwiperService;
import cn.yj.entity.R;
import cn.yj.tools.readconfig.PropertiesUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

/**
 * @author 永健
 * @since 2021-05-29 13:06
 */
@RequestMapping("/common")
@RestController
public class CommonController extends AppBaseController {

    @Resource
    private SwiperService swiperService;

    @Resource
    private ConcatInfo concatInfo;

    /**
     * 骗微信审核
     */
    @Anonymous
    @GetMapping("/isStart")
    public R isStart() {
        return success(PropertiesUtils.getBooleanValue("school-cbd.start-dongtai", false));
    }


    /**
     * 开启公众号
     */
    @Anonymous
    @GetMapping("/startMp")
    public R startGift() {
        return success(PropertiesUtils.getBooleanValue("school-cbd.start-mp", false));
    }


    @Anonymous
    @GetMapping("/indexNotice")
    public R indexNotice() {
        return success(PropertiesUtils.getStringValue("school-cbd.index-notice-msg"));
    }

    @Anonymous
    @GetMapping("/activityBoolean")
    public R activityBoolean() {
        return success(getMap("start", PropertiesUtils.getBooleanValue("school-cbd.enable-activity")));
    }


    /**
     * 问题帮助
     */
    @Anonymous
    @GetMapping("/question.html")
    public R questionHtml() {
        try {
            String fileContent = FileUtils.getFileContent("classpath:html/question.html", this.getClass());
            return success(fileContent);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return success();
    }

    /**
     * 问题帮助
     */
    @Anonymous
    @GetMapping("/about.html")
    public R aboutMeHtml() {
        try {
            String fileContent = FileUtils.getFileContent("classpath:html/about-me.html", this.getClass());
            return success(fileContent);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return success();
    }

    @Anonymous
    @GetMapping("/gift.html")
    public R giftHtml() {
        try {
            String fileContent = FileUtils.getFileContent("classpath:html/gift.html", this.getClass());
            return success(fileContent);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return success();
    }


    /**
     * 联系我们 页面数据
     */
    @GetMapping("/concatMeInfo")
    @Anonymous
    public R concatMeInfo() {
        return success(concatInfo.getInfo());
    }

    @GetMapping("/getSwiper")
    @Anonymous
    public R getSwiper() {
        return success(swiperService.listSwiper());
    }
}
